<?php
class home extends Activity {
    public function __construct(){
        $this->user=UserModule::init("user");
    } 
  
    function indexTask(){
        $goods=GoodsMode::init();
        $cats=MenuModule::init();
        $ad = AdMode::init();
        $parents=$cats->getSon(0);
        usort($parents,function($a,$b){
            return -$a['point']+$b['point'];
        });
        foreach ($parents as &$v) {
            $tmp=$cats->getPosterity($v['id']);
            $son_cat_ids=is_array($tmp)?implode(',',$tmp):$tmp;
            list($v['goods'],$v['total'])=$goods->getList(null,null,$son_cat_ids,null,'',false,8,0);
        }
        foreach ($parents as &$v) {
            if(!empty($v['goods'])){
                $v['goods']=$goods->getSimpleInfo($v['goods']);
            }
        }
        $likeIds = $goods->getList(null,3,null,null,'',false,8,0);
        $r['normal']=$parents;
        list($r['ad'],$total)=$ad->getList();
        $r['like']=$goods->getDetailInfo($likeIds[0]);
        View::displayAsHtml($r,"index.php");
    }
    function serviceTask(){
        $result=array();
        View::displayAsHtml($result, "home-service.php");
    }

    function weatherTask(){
        $result=array();
        View::displayAsHtml($result, "home-weather.php");
    }
    function feeTask(){
        $result=array();
        View::displayAsHtml($result, "home-fee.php");
    }

    function headerTask(){
        //设置cookie_site_id
          //1.获取当前ip所代表的地址
         /*$commonMode= CommonMode::init();
        $ipInfos = $commonMode->GetIpLookup(); 
        if(!$ipInfos){
            $ipInfos['city']="北京";
        }*/
        //根据城市获取site_id
       /* $region_id=$commonMode->get_regionid($ipInfos['city']);
        $sitemode=SiteMode::init()->get_siteid($region_id); */
        
        $result['label']=GoodsMode::init()->getLabelByPlace('box');
          //获取site数据
        $result['sitemodes']=CommonMode::init()->get_site();
        $result['sitename']=CommonMode::init()->get_sitename();
        View::displayAsHtml($result, "fragment/header.php");
    }

    function userBarTask(){
        $um=$this->user;
        $u=UserMode::init();
        $result['ifLogin']=$um->checkLogin();
        if($result['ifLogin']){
            $result['id'] =$um->getLoginId();
            $result['user']=$um->getLoginInfo();
            $result['info']=$u->getDetail($result['id']);
            $result['lv']=$u->getLvInfo($result['info']['lv_id']);
            $result['cart']=(int)CartMode::init()->getNumber($result['id']);
        }
        View::displayAsHtml($result, "fragment/userbar.php");
    }
    function leftSlideTask(){
        View::displayAsHtml(array(),"fragment/leftSlide.php");
    }
    //测试用
    function testTask(){
        View::displayAsHtml(array(), "test.html");
    }
}